require 'sketchup.rb'
module AMTF
  unless file_loaded?(__FILE__)
    menu = UI.menu('Plugins')
    menu.add_item('amtf_su') {
      # self.主页
      AMTF::AMTF窗口.new
    }
    file_loaded(__FILE__)
  end
  class AMTF窗口 < UI::WebDialog
    def initialize
      # Dialog parameters
      super "amtf", false, "amtf", 350, 600, 50, 100, true
      path = File.join(__dir__, '/amtf_su.html')
      set_file path
      navigation_buttons_enabled = false
      min_width = 50
      min_height = 50

      # Set the WebDialog's callback
      add_action_callback("hei") {|dialog, arg|
          puts arg
      }
      add_action_callback("重载ABF") {|dialog, arg|
        path = Sketchup.find_support_file "abf_solutions/startup.rb", "Plugins"
        puts "path=" + path.to_s
        load path.to_s
        puts "重新加载ABFing……稍安勿躁……"
      }
      add_action_callback("你好么") {|dialog, arg|
          puts arg
      }
      add_action_callback("刷新amtf") {|dialog, arg|
        AMTF::reload
        puts arg+" 完成！"
      }
      add_action_callback("匹配尺寸") {|dialog, arg|
        Sketchup.active_model.select_tool AF匹配尺寸.new
      }
      add_action_callback("对齐") {|dialog, arg|
        # Sketchup.active_model.select_tool( AF对齐.new )
        Sketchup.active_model.select_tool AF对齐.new
      }
      add_action_callback("画柜子") {|dialog, arg|
        # p "hello"
        Sketchup.active_model.select_tool AF画柜子.new(arg+".skp")
      }
      add_action_callback("另存排版") {|dialog, arg|
        AF另存排版.new()
        p 'ok'
      }

      # Display the dialog box
      if RUBY_PLATFORM.index "darwin"
        show_modal
      else
        show
      end

    end
  end #AMTF窗口

  #作废保留
    def self.主页
      # Create the WebDialog and set its HTML file
      options = {
        :dialog_title => 'amtf',
        :scrollable => true,
        :resizable => true,
        :width => 350,
        :height => 600,
        :left => 20,
        :top => 100,
        :min_width => 50,
        :min_height => 50,
        # :max_width =>1000,
        # :max_height => 500,
        :style => UI::HtmlDialog::STYLE_DIALOG
      }
      dialog = UI::WebDialog.new(options)
      # path = Sketchup.find_support_file "amtf_su/amtf_su.html", "Plugins"
      path = File.join(__dir__, '/amtf_su.html')
      dialog.set_file path
      # Set the WebDialog's callback
      dialog.add_action_callback("hei") {|dialog, arg|
          puts arg
      }
      dialog.add_action_callback("重载ABF") {|dialog, arg|
        path = Sketchup.find_support_file "abf_solutions/startup.rb", "Plugins"
        puts "path=" + path.to_s
        load path.to_s
        puts "重新加载ABFing……稍安勿躁……"
      }
      dialog.add_action_callback("你好么") {|dialog, arg|
          puts arg
      }
      dialog.add_action_callback("刷新amtf") {|dialog, arg|
        AMTF::reload
        puts arg+" 完成！"
      }
      dialog.add_action_callback("匹配尺寸") {|dialog, arg|
        Sketchup.active_model.select_tool AF匹配尺寸.new
      }
      dialog.add_action_callback("对齐") {|dialog, arg|
        # Sketchup.active_model.select_tool( AF对齐.new )
        Sketchup.active_model.select_tool AF对齐.new
      }
      dialog.add_action_callback("画柜子") {|dialog, arg|
        # p "hello"
        Sketchup.active_model.select_tool AF画柜子.new(arg+".skp")
      }

      # Display the dialog box
      if RUBY_PLATFORM.index "darwin"
        dialog.show_modal
      else
        dialog.show
      end
    end


end # module amtf_su
